{template 'web/_header'}
{template 'tabs'}
<div class='alert alert-info'>
    提示：没有设置等级的分销商将按默认设置计算提成。商品指定的佣金金额的优先级仍是最高的，也就是说只要商品指定了佣金金额就按商品的佣金金额来计算，不受等级影响。<br />
    其次：若用户满足下面多个等级的升级条件时，系统将以权重最高的等级作为升级等级。
</div>
{if $operation == 'post'}
<div class="main">
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <input type="hidden" name="id" value="{$level['id']}" />
        <div class='panel panel-default'>
            <div class='panel-heading'>
                分销商等级设置
            </div>
            <div class='panel-body'>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 等级名称</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="levelname" class="form-control" value="{$level['levelname']}" />
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"> 等级权重</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="priority" class="form-control" value="{$level['priority']}" />
                        <span class='help-block'>等级权重，权重越高，代表等级越高。</span>
                    </div>
                </div>

                {if $this->set['level']>=1}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">一级分销比例</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="commission1" class="form-control" value="{$level['commission1']}" />
                    </div>
                </div>
                {/if}

                {if $this->set['level']>=2}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">二级分销比例</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="commission2" class="form-control" value="{$level['commission2']}" />
                    </div>
                </div>
                {/if}

                {if $this->set['level']>=3}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">三级分销比例</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="commission3" class="form-control" value="{$level['commission3']}" />
                    </div>
                </div>
                {/if}

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">此等级升级依据</label>
                    <div class="col-sm-9 col-xs-12">
                        <select  class="form-control" name="leveltype">
                            <option value="ordersum" {if $set['leveltype'] == 'ordersum' || $set['leveltype'] == ''} selected{/if}>自购订单总额(完成的订单)</option>
                            <option value="ordercount" {if $set['leveltype'] == 'ordercount'} selected{/if}>自购订单总数(完成的订单)</option>
                            <option value="agentordersum" {if $set['leveltype'] == 'agentordersum'} selected{/if}>分销订单总额(完成的订单)</option>
                            <option value="agentordercount" {if $set['leveltype'] == 'agentordercount'} selected{/if}>分销订单总数(完成的订单)</option>
                            <option value="agent1ordersum" {if $set['leveltype'] == 'agent1ordersum'} selected{/if}>一级分销订单总额(完成的订单)</option>
                            <option value="agent1ordercount" {if $set['leveltype'] == 'agent1ordercount'} selected{/if}>一级分销订单总数(完成的订单)</option>
                            <option value="agentallcount" {if $set['leveltype'] == 'agentallcount'} selected{/if}>下线总人数（分销商 + 非分销商）</option>
                            <option value="agentcount" {if $set['leveltype'] == 'agentcount'} selected{/if}>下线总人数（分销商）</option>
                            <option value="agent1allcount" {if $set['leveltype'] == 'agent1allcount'} selected{/if}>一级下线总人数（分销商 + 非分销商）</option>
                            <option value="agent1count" {if $set['leveltype'] == 'agent1count'} selected{/if}>一级下线总人数（分销商）</option>
                            <option value="ordersum:agent1ordersum" {if $set['leveltype'] == 'ordersum:agent1ordersum'} selected{/if}>自购订单总额 或 一级分销订单金额(完成的订单，若开启分销内购时，此处无作用。)</option>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">达到指定依据的值</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="value" class="form-control" value="{$level['value']}" />
                        <span class='help-block'>分销商升级条件，不填写默认为不自动升级</span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否脱离上级</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class="radio-inline"><input type="radio" name="split" value="0" {if $level['split'] == 0 }checked="checked"{/if} > 关闭</label>
                        <label class="radio-inline"><input type="radio" name="split" value="1" {if $level['split'] == 1 }checked="checked"{/if}> 开启</label>
                        <span class="help-block">若开启，当用户升级时，将脱离原上级关系，并带走其下线的所有人。(慎用)</span>
                    </div>
                </div>

            </div>
        </div>
        <div class="form-group col-sm-12">
	<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
	<input type="hidden" name="token" value="{$_W['token']}" />
	</div>
    </form>
</div>
<script language='javascript'>
    $('form').submit(function(){
        if($(':input[name=levelname]').isEmpty()){
            Tip.focus($(':input[name=levelname]'),'请输入等级名称!');
            return false;
        }
        return true;
    })
    </script>
{elseif $operation == 'display'}
            <form action="" method="post" onsubmit="return formcheck(this)">
     <div class='panel panel-default'>
            <div class='panel-heading'>
                分销商等级设置
            </div>
         <div class='panel-body'>
   
            <table class="table">
                <thead>
                    <tr>
                        <th>等级名称</th>
                        {if $this->set['level']>=1}<th>一级比例</th>{/if}
                        {if $this->set['level']>=2}<th>二级比例</th>{/if}
                        {if $this->set['level']>=3}<th>三级比例</th>{/if}
                        <th>升级条件</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {loop $list $row}
                    <tr>
                        <td>{$row['levelname']}</td>

                        {if $this->set['level']>=1}
                        <td>{$row['commission1']}%</td>
                        {/if}

                        {if $this->set['level']>=2}
                        <td>{$row['commission2']}%</td>
                        {/if}

                        {if $this->set['level']>=3}
                        <td>{$row['commission3']}%</td>
                        {/if}

                        <td>
                        {if $row['value'] > 0}
                            {if $row['leveltype'] == 'ordersum'}自购订单总额(完成的订单) {$row['value']} 元
                            {else if $row['leveltype'] == 'ordercount'}自购订单总数(完成的订单) {php echo intval($row['value'])} 单
                            {else if $row['leveltype'] == 'agentordersum'}分销订单总额(完成的订单) {$row['value']} 元
                            {else if $row['leveltype'] == 'agentordercount'}分销订单总数(完成的订单) {php echo intval($row['value'])} 单
                            {else if $row['leveltype'] == 'agent1ordersum'}一级分销订单金额(完成的订单) {$row['value']} 元
                            {else if $row['leveltype'] == 'agent1ordercount'}一级分销订单总数(完成的订单) {php echo intval($row['value'])} 单
                            {else if $row['leveltype'] == 'agentallcount'}下线总人数（分销商 + 非分销商）{php echo intval($row['value'])} 人
                            {else if $row['leveltype'] == 'agentcount'}下线总人数（分销商）{php echo intval($row['value'])} 人
                            {else if $row['leveltype'] == 'agent1allcount'}一级下线总人数（分销商 + 非分销商）{php echo intval($row['value'])} 人
                            {else if $row['leveltype'] == 'agent1count'}一级下线总人数（分销商）{php echo intval($row['value'])} 人
                            {else if $row['leveltype'] == 'ordersum:agent1ordersum'}自购订单总额 或 一级分销订单金额(完成的订单) {$row['value']} 元
                            {else}自购订单总额(完成的订单) {$row['value']} 元
                            {/if}
                        {else}
                            不自动升级
                        {/if}
                        </td>

                        <td>
                            <a class='btn btn-default' href="{php echo $this->createPluginWebUrl('commission/level', array('op' => 'post', 'id' => $row['id']))}">编辑</a>
                            <a class='btn btn-default'  href="{php echo $this->createPluginWebUrl('commission/level', array('op' => 'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此等级吗？');return false;">删除</a>
                        </td>

                    </tr>
                    {/loop}
                
                </tbody>
            </table>

         </div>
         <div class='panel-footer'>
            <a class='btn btn-default' href="{php echo $this->createPluginWebUrl('commission/level', array('op' => 'post'))}"><i class="fa fa-plus"></i> 添加新等级</a>
         </div>
     </div>
         </form>
{/if}
{template 'common/footer'}
